Skip to content

Add transport worker factory and abstract base class for background worker #4580

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: srothh/transport-class-hierarchy
Choose a base branch
from

Conversation

srothh
Copy link
Member

@srothh srothh commented Jul 14, 2025

Add a new abstract base class for the background worker implementations in the transport. This allows for implementation of the upcoming async task-based worker in addition to the current thread based worker used in the sync context. Additionally, add a factory method in the HttpTransportCore shared class, to allow the worker methods to live higher up in the class hierarchy regardless of specific implementation.

GH-4578

Copy link

codecov bot commented Jul 14, 2025

Codecov Report

❌ Patch coverage is 78.26087% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 84.98%. Comparing base (4e56e5c) to head (ef780f3).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
sentry_sdk/worker.py 73.68% 5 Missing ⚠️
Additional details and impacted files
@@                         Coverage Diff                          @@
##           srothh/transport-class-hierarchy    #4580      +/-   ##
====================================================================
+ Coverage                             83.70%   84.98%   +1.28%     
====================================================================
  Files                                   158      158              
  Lines                                 15395    15414      +19     
  Branches                               2432     2432              
====================================================================
+ Hits                                  12886    13100     +214     
+ Misses                                 1755     1561     -194     
+ Partials                                754      753       -1     
Files with missing lines Coverage Δ
sentry_sdk/transport.py 86.14% <100.00%> (+0.07%) ⬆️
sentry_sdk/worker.py 81.08% <73.68%> (+3.42%) ⬆️

... and 13 files with indirect coverage changes

@srothh
Copy link
Member Author

srothh commented Jul 14, 2025

Codecov Report

Attention: Patch coverage is 78.26087% with 5 lines in your changes missing coverage. Please review.

Project coverage is 84.90%. Comparing base (fe27100) to head (a6be4a3).

✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
sentry_sdk/worker.py 73.68% 5 Missing ⚠️
Additional details and impacted files

The uncovered lines of code here are just the pass calls from the abstract class definition.

@srothh srothh force-pushed the srothh/transport-class-hierarchy branch from 53b92f2 to 3607d44 Compare July 21, 2025 09:48
@srothh srothh force-pushed the srothh/worker-class-hierarchy branch 2 times, most recently from 2896602 to 268ea1a Compare July 23, 2025 14:02
@srothh srothh marked this pull request as ready for review July 24, 2025 07:49
@srothh srothh requested a review from a team as a code owner July 24, 2025 07:49
Copy link
Member

@antonpirker antonpirker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you add some docstrings, this is fine to merg!

@property
@abstractmethod
def is_alive(self) -> bool:
pass
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add docstrings to all methods in the new abstract worker class.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, thanks!

@srothh srothh force-pushed the srothh/transport-class-hierarchy branch from 062ab5b to 4e56e5c Compare July 28, 2025 08:48
srothh added 6 commits July 28, 2025 10:55
Add an abstract bass class for implementation of the background worker. This was done to provide a shared interface for the current
implementation of a threaded worker in the sync context as well as the upcoming async task-based worker implementation.

GH-4578
Add a new factory method instead of direct instatiation of the threaded background worker.
This allows for easy extension to other types of workers, such as the upcoming task-based async worker.

GH-4578
Add a new flush_async method to worker ABC. This is necessary because the async transport cannot use a
synchronous blocking flush.

GH-4578
Move the flush_async down to the concrete subclass to not break existing testing. This makes sense,
as this will only really be needed by the async worker anyway and therefore is not shared logic.

GH-4578
Coroutines have a return value, however the current function signature for the worker methods does not
accomodate for this. Therefore, this signature was changed.

GH-4578
@srothh srothh force-pushed the srothh/worker-class-hierarchy branch from 1fbf85f to ef780f3 Compare July 28, 2025 08:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants